#ifndef PLAYGROUND_H
#define PLAYGROUND_H

#include <QtGui>
#include "commons.h"

class Playground : public QObject, public QGraphicsItem
{
    Q_OBJECT
    Q_INTERFACES(QGraphicsItem)
public:
    explicit Playground(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    QRectF boundingRect() const;

    void setPlayLevel(Level*level);
    Level *getCurrentLevel();
signals:
    void returnClicked();
    void pointHoverEnter();
    void pointHoverLeave();
    void lineHoverEnter();
    void lineHoverLeave();
    void pointDragStart();
    void pointDragStop();
    void lineDragStart();
    void lineDragStop();
    void toNextLevel();

public slots:
    void clicked(ButtonItem *who);
    void pointHoverEntered();
    void pointHoverLeft();
    void lineHoverEntered();
    void lineHoverLeft();
    void pointDragStarted();
    void pointDragStoped();
    void lineDragStarted();
    void lineDragStoped();
    void nextLevel();

private:
    ImageItem *background;
    ImageItem *greatImg;
    ButtonItem *returnBg;
    Canvas *canvas;
    GraphJudger *judger;
    QTimer *timer;
    Level *current;

    void initScene();
    void initEventSystem();
    void doSolved();

};

#endif // PLAYGROUND_H
